import { Suspense } from 'react';

import { Redirect, Route, Switch } from 'react-router-dom';
import PrivateRoute from '../components/PrivateRoute';
import login from './routes/login';
import admin from './routes/admin';


export const createLoginRoute = () => {
  return <Route {...login} />
}

export const createAdminRoute = () => {
  // console.log(111)
  return < PrivateRoute path={admin.path} component={admin.component} />
}
// admin子路由
export const createChildrenAdminRoute = () => {
  return (
    <Suspense fallback={<div>loading...</div>}>
      <Switch>
        {
          admin.children.map(item => (
            < PrivateRoute key={item.path} path={item.path} component={item.component} />
          ))
        }
      </Switch>
    </Suspense>
  )
}

export const createRoute = () => {
  return (
    <Suspense fallback={<div>loading...</div>}>
      <Switch>
        {createLoginRoute()}
        {createAdminRoute()}

        <Redirect to='/login' />
      </Switch>
    </Suspense>
  )
}